/**
* Created with CLion.
* User:Lenovo
* Date:2023-04-19
* Time:12:40
* Description:单链表
*/

//针对顺序表的其他解决方案
// 1.不扩容
// 2.按需申请释放
// 3.解决头部或者中间位置的插入删除，挪动数据的问题 -> 一块连续的物理空间

#include "SList.h"

void TestSList1()
{
    SLTNode *pList = NULL;
    SLPushFront(&pList, 1);
    SLPushFront(&pList, 2);
    SLPushFront(&pList, 3);
    SLPushFront(&pList, 4);

    SLTPrint(pList);
}

void TestSList2()
{
    SLTNode *pList = NULL;
    SLPushBack(&pList, 1);
    SLPushBack(&pList, 2);
    SLPushBack(&pList, 3);
    SLPushBack(&pList, 4);

    SLTPrint(pList);
}

void TestSList3()
{
    SLTNode *pList = NULL;
    SLPushBack(&pList, 1);
    SLPushBack(&pList, 2);
    SLPushBack(&pList, 3);
    SLPushBack(&pList, 4);
    SLTPrint(pList);

    SLPopBack(&pList);
    SLTPrint(pList);
    SLPopBack(&pList);
    SLTPrint(pList);
    SLPopBack(&pList);
    SLTPrint(pList);
    SLPopBack(&pList);
    SLTPrint(pList);
}

void TestSList4()
{
    SLTNode *pList = NULL;
    SLPushBack(&pList, 1);
    SLPushBack(&pList, 2);
    SLPushBack(&pList, 3);
    SLPushBack(&pList, 4);
    SLTPrint(pList);

    SLPopFront(&pList);
    SLTPrint(pList);
    SLPopFront(&pList);
    SLTPrint(pList);
    SLPopFront(&pList);
    SLTPrint(pList);
    SLPopFront(&pList);
    SLTPrint(pList);
}

void TestSList5()
{
    SLTNode *pList = NULL;
    SLPushBack(&pList, 1);
    SLPushBack(&pList, 2);
    SLPushBack(&pList, 3);
    SLPushBack(&pList, 4);
    SLTPrint(pList);

    SLTNode *pos = STFind(pList, 3);
    pos -> data = 30;//同时也是修改
    SLTPrint(pList);
}

void TestSList6()
{
    SLTNode *pList = NULL;
    SLPushBack(&pList, 1);
    SLPushBack(&pList, 2);
    SLPushBack(&pList, 3);
    SLPushBack(&pList, 4);
    SLTPrint(pList);

    SLTNode *pos = STFind(pList, 3);
    if (pos)
    {
        SLInsert(&pList, pos, 30);
    }
    SLTPrint(pList);

    pos = STFind(pList, 2);
    if (pos)
    {
        SLInsertAfter(pos, 20);
    }
    SLTPrint(pList);
}

void TestSList7()
{
    SLTNode *pList = NULL;
    SLPushBack(&pList, 1);
    SLPushBack(&pList, 2);
    SLPushBack(&pList, 3);
    SLPushBack(&pList, 4);
    SLTPrint(pList);

    SLTNode *pos = STFind(pList, 3);
    SLErase(&pList, pos);
    SLTPrint(pList);

    pos = STFind(pList, 2);
    SLEraseAfter(pos);
    SLTPrint(pList);

    SLDestroy(&pList);
}

int main()
{
    TestSList1();
    TestSList2();
    TestSList3();
    TestSList4();
    TestSList5();
    TestSList6();
    TestSList7();

    return 0;
}

